<template>
  <!-- 搜索视频 -->
  <div class="sc-video">
    <search-not-found v-if="!found"></search-not-found>
    <div v-if="found">
      <div ref="mvsMain" class="mvs-main">
        <ul class="mvs-main-list clearfix">
          <li class="mvs-main-item" v-for="item in videos" :key="item.id">
            <mv-list v-if="item.type == 0" :item="item"></mv-list>
            <video-list
              v-if="item.type == 1"
              :item="item"
              :showTime="false"
            ></video-list>
          </li>
        </ul>
      </div>
      <div class="mvs-el-pagination" v-if="videoCount > 30">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="30"
          layout="prev, pager, next, jumper"
          :total="videoCount"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import MvList from "components/mvlist/MvList.vue";
import VideoList from "components/videolist/VideoList.vue";
import SearchNotFound from "views/search/child/SearchNotFound";

export default {
  components: {
    MvList,
    VideoList,
    SearchNotFound,
  },
  data() {
    return {
      videos: [],
      currentPage: 1,
      videoCount: 0,
      found: true,
    };
  },
  mounted() {
    this.getSearchVideo();
  },
  methods: {
    handleCurrentChange() {
      this.getSearchVideo();
      document.documentElement.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
    getSearchVideo() {
      this.axios({
        url:
          "/cloudsearch?type=1014&keywords=" +
          this.$store.state.MInput +
          "&offset=" +
          (this.currentPage - 1) * 30,
      })
        .then((res) => {
          if (!res.data.result || res.data.result.videoCount == 0) {
            this.found = false;
          } else {
            this.videos = res.data.result.videos;
            this.videoCount = res.data.result.videoCount;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.sc-video {
  margin-bottom: 50px;
  padding: 20px;
  overflow: hidden;
}
.sc-video .mvs-main-list {
  margin-right: -20px;
  margin-bottom: 50px;
}
.sc-video .mvs-main-item {
  float: left;
  width: 20%;
}
.sc-video .mvs-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto;
}
</style>